import numpy as np
import matplotlib.pyplot as plt

dataset = np.array([[0, 6], [1, 0], [2, 0]])  # column之间独立

if __name__ == '__main__':
    # 仿射
    A = np.array([[1, 0], [1, 1], [1, 2]])
    b = np.array([6, 0, 0])

    solution = np.dot(np.dot(np.linalg.inv(np.dot(A.T, A)), A.T), b)

    fig = plt.figure()

    plt.subplot(121)
    plt.scatter(A[:, 1], b)
    plt.title('dataset')

    plt.subplot(122)
    x = np.arange(0, 2, 0.5)
    y = solution[0] + solution[1] * x
    plt.plot(x, y)
    plt.scatter(A[:, 1], b)
    plt.title('Least-Square y={}{}x'.format(solution[0], solution[1]))

    plt.show()